package com.baichang.taoshunda.controller.mobile.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.RecommendCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.ParseException;

/**
 * Created by Administrator on 2018/1/29 0029.
 */
@Controller
@RequestMapping(ControllerConstants.RECOMMEND)
public class BusinessRecommendMController extends BaseMobileController {

    @Autowired
    private RecommendCompanyService recommendCompanyService;

    /**
     * 添加推荐商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/addRecommendBus")
    public void addRecommendBus(HttpServletRequest request, HttpServletResponse response) {
       initEncode(request, response, new IService() {
           @Override
           public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
               Integer busId = getInt(json, "busId", 0);
               Integer month = getInt(json, "month", 0);  //轮播图月份
               BigDecimal price = BigDecimal.valueOf(getDouble(json, "price", 0));  //金额
               return recommendCompanyService.addRecommendBus(busId, month, price);
           }
       });
    }

    /**
     * 查询我的推荐商家
     *
     * @param request
     * @param response
     */
    @RequestMapping("/queryRecommendBusDetails")
    public void queryRecommendBusDetails(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                Integer busId = getInt(json, "busId", 0);
                try {
                    return recommendCompanyService.queryRecommendBusDetails(busId);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
    }
}
